package com.ruoyi.eduadmin.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.eduadmin.service.IItStudentesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.eduadmin.domain.ItFocus;
import com.ruoyi.eduadmin.service.IItFocusService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 重点关注Controller
 * 
 * @author ruoyi
 * @date 2022-12-28
 */
@RestController
@RequestMapping("/focus")
public class ItFocusController extends BaseController
{
    @Autowired
    private IItFocusService itFocusService;
    @Autowired
    private IItStudentesService itStudentesService;

    /**
     * 查询重点关注列表
     */
    @RequiresPermissions("eduadmin:focus:list")
    @GetMapping("/list")
    public TableDataInfo list(ItFocus itFocus)
    {
        startPage();
        List<ItFocus> list = itFocusService.selectItFocusList(itFocus);
        return getDataTable(list);
    }

    /**
     * 导出重点关注列表
     */
    @RequiresPermissions("eduadmin:focus:export")
    @Log(title = "重点关注", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ItFocus itFocus)
    {
        List<ItFocus> list = itFocusService.selectItFocusList(itFocus);
        ExcelUtil<ItFocus> util = new ExcelUtil<ItFocus>(ItFocus.class);
        util.exportExcel(response, list, "重点关注数据");
    }

    /**
     * 获取重点关注详细信息
     */
    @RequiresPermissions("eduadmin:focus:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(itFocusService.selectItFocusById(id));
    }

    /**
     * 新增重点关注
     */
    @RequiresPermissions("eduadmin:focus:add")
    @Log(title = "重点关注", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ItFocus itFocus)
    {
        return toAjax(itFocusService.insertItFocus(itFocus));
    }

    /**
     * 修改重点关注
     */
    @RequiresPermissions("eduadmin:focus:edit")
    @Log(title = "重点关注", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ItFocus itFocus)
    {
        return toAjax(itFocusService.updateItFocus(itFocus));
    }

    /**
     * 删除重点关注
     */
    @RequiresPermissions("eduadmin:focus:remove")
    @Log(title = "重点关注", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        for (Long id : ids) {
            ItFocus itFocus = itFocusService.selectItFocusById(id);
            itStudentesService.changeFocus(itFocus.getStudentId(), 0);
        }
        return toAjax(itFocusService.deleteItFocusByIds(ids));
    }
}
